home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / prgs / ShellUtils / cp.b < prev    next >
Text File  |  1996-09-10  |  2KB  |  43 lines

  1.           {* 
  2.       ** This program copies a source file to a destination file
  3.       ** using dos.library functions for speed.
  4.       ** Originally written as an example program for an ACE user
  5.       ** in Budapest! The current version has better error reporting
  6.       ** and handles command-line arguments.
  7.       **
  8.       ** Author: David J Benn
  9.       **   Date: 29th December 1994
  10.       *}
  11.       DECLARE FUNCTION _Read&(fh,buf,length) LIBRARY dos 
  12.           DECLARE FUNCTION _Write&(fh,buf,length) LIBRARY dos 
  13.       SUB usage
  14.         PRINT "usage: ";ARG$(0);" src dest"
  15.         STOP
  16.       END SUB
  17.           SUB ReportError(n) 
  18.         CASE
  19.         n = 1 : PRINT "Unable to open source file."
  20.         n = 2 : PRINT "Source file empty."
  21.         n = 3 : PRINT "Unable to allocate memory for source file buffer."
  22.         n = 4 : PRINT "Error while reading from source file."
  23.         n = 5 : PRINT "Unable to open destination file."
  24.         n = 6 : PRINT "Error while writing to destination file."
  25.         END CASE
  26.             CLOSE #1 : STOP 
  27.           END SUB 
  28.           ADDRESS fh, buf 
  29.           LONGINT length 
  30.       IF ARGCOUNT <> 2 THEN CALL usage
  31.           src$ = ARG$(1) : dest$ = ARG$(2)
  32.           OPEN "I",#1,src$ 
  33.           fh = HANDLE(1) : IF fh = 0 THEN CALL ReportError(1) 
  34.           length = LOF(1) : IF length = 0 THEN CALL ReportError(2) 
  35.           buf = ALLOC(length) : IF buf = 0 THEN CALL ReportError(3) 
  36.           IF _Read(fh,buf,length) <> length THEN CALL ReportError(4) 
  37.           CLOSE #1 
  38.           OPEN "O",#1,dest$ 
  39.           fh = HANDLE(1) : IF fh = 0 THEN CALL ReportError(5) 
  40.           IF _Write(fh,buf,length) <> length THEN CALL ReportError(6) 
  41.           CLOSE #1 
  42.           END
  43.